package com.quan.commons.pojo;

import java.util.Map;

/**
 * 自定义响应数据结构
 * 200：表示成功
 * 500：表示错误，错误信息在msg字段中
 * @author yhaoquan
 *
 */
public class JSONResult {

	/**
     * 响应状态
     */
    private Boolean flag ;

    /**
     * 响应业务状态码
     */
    private Integer status ;

    /**
     * 响应消息
     */
    private String msg ;

    /**
     * 响应数据
     */
    private Object data ;

    /**
     * 其他属性数据
     */
    private Map<String, Object> attrs ;
    
    /**
     * 当前时间
     */
    private Long timestamp = System.currentTimeMillis() ;
    
    public static JSONResult build(Boolean flag, Integer status, String msg, Object data, Map<String, Object> attrs) {
    	return new JSONResult(flag, status, msg, data, attrs) ;
    }
    
    public static JSONResult build(Boolean flag, Integer status, String msg, Object data) {
    	return new JSONResult(flag, status, msg, data, null) ;
    }
    
    public static JSONResult ok(Object data) {
    	return new JSONResult(true, 200, "ok", data, null) ;
    }
    
    public static JSONResult ok() {
    	return new JSONResult(true, 200, "ok", null, null) ;
    }
    
    public static JSONResult errorMsg() {
    	return new JSONResult(false, 500, "error", null, null) ;
    }
    
    public static JSONResult errorMsg(String msg) {
    	return new JSONResult(false, 500, msg, null, null) ;
    }
    
    public static JSONResult errorMsg(Object data) {
    	return new JSONResult(false, 500, "error", data, null) ;
    }
    
    public static JSONResult errorException(String msg) {
    	return new JSONResult(false, 500, msg, null, null) ;
    }
    
    public static JSONResult errorException(Integer status, String msg) {
    	return new JSONResult(false, status, msg, null, null) ;
    }
    
    public JSONResult() {}

	public JSONResult(Boolean flag, Integer status, String msg, Object data, Map<String, Object> attrs) {
		super();
		this.flag = flag;
		this.status = status;
		this.msg = msg;
		this.data = data;
		this.attrs = attrs;
	}
	
	public JSONResult(Boolean flag, Integer status, String msg, Object data) {
		super();
		this.flag = flag;
		this.status = status;
		this.msg = msg;
		this.data = data;
	}

	public JSONResult(Boolean flag, Integer status, String msg) {
		super();
		this.flag = flag;
		this.status = status;
		this.msg = msg;
	}
	
	
	public Boolean getFlag() {
		return flag;
	}

	public void setFlag(Boolean flag) {
		this.flag = flag;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public Map<String, Object> getAttrs() {
		return attrs;
	}

	public void setAttrs(Map<String, Object> attrs) {
		this.attrs = attrs;
	}

	public Long getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(Long timestamp) {
		this.timestamp = timestamp;
	}
	
}
